package com.it.day5;

import java.util.concurrent.TimeUnit;

/**
 * ClassName: VolatileSeeDemo
 * Description: volatile使用场景
 *
 * @Author: csx
 * @Create: 2025/5/12 - 14:13
 * @version: v1.0
 */
public class VolatileSeeDemo {
    static volatile boolean falg = true;

    public static void main(String[] args) {
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + " 线程正在执行！");
            while (falg);
            System.out.println("-----------falg被修改 " + Thread.currentThread().getName() + " 线程执行完毕！");
        },"t1").start();

        try { TimeUnit.SECONDS.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); }

        falg = false;
        System.out.println("main线程修改了falg");
    }
}
















